


	use  MxFLS_final , clear		
	
/* select sample   */ 
		
	keep if hhpotentialmigration ==1 
	keep if statusliving05==1 		
	keep if age >14 
	
	
	g young   =  age <=25   
	g old    = age>=26 
	g treat_male= treatment* male
	g treat_female= treatment* female
	g treat_young= treatment* young
	g treat_old= treatment*  old 

	
/* indepedent variables   */
	
	#delimit ; 

	global indivlist   female  age age_female   yedu  single   ;  
	global hhlist     		
				ln_socialnonlabincome   						  
				hh_higestgrade3  hh_higestgrade4
				wealthindex  wealthindexsq  
				hhsize     nbage13minus 
				hhrelativeUS hhreturnees
				 ARRIVE_age6less    
				LEAVE_age6less 
	; 
	global shocks dead_0205 disease_0205 job_busi_failure_0205 loss_crop_0205 robb_naturaldis_0205  ///
				  dead_0298  disease_0298 job_busi_failure_0298 loss_crop_0298 robb_naturaldis_0298 ;

	global indep_M2     ${indivlist}   ${hhlist}  ${mun_list2} ${shocks}   ;	
	
	global mig_control hhmexmigrant   hh_newmem_adu  ;
  
	global model_list  M2   ;


	  
/* depedent variables 	*/

		
	global HH_CONSPERCAP   	UnearnedINC0502 food_attana_0502 nonfood_attana_0502  cons_attana_0502    ;  
    global assets_ext  HH_ownfinancialassets0502	HH_ownbicycle0502 	HH_ownmotorvehic0502 	
						 HH_ownelecdevice0502 	HH_ownwashingmachine0502 HH_owndomesappliance0502
						 HH_own_draftanimal0502   HH_own_productanimal0502 HH_ownequipement0502 ;			
	global input_ext     HH_POS_soil_input0502     HH_POS_otherland_input0502  ;
	global input_ext_long       HH_POS_soil_input0902     HH_POS_otherland_input0902  ;
	global input_int_long      HH_soil_input0902     	 HH_otherland_input0902 	;

	global HH_CONSPERCAP_long   cons_precap_0902    cons_rojas_0902 food_attana_0902 nonfood_attana_0902  cons_attana_0902   HH_nbsize0902 HH_nbadult0902   ;  
  
  
	global farmincome	farm_prod_ph_0502 farm_prod_pw_0502 farm_incap_0502 farm_prod_ph_0902 farm_prod_pw_0902 farm_incap_0902 
		HH_incomemonth_self0502 HH_incomemonth_self0902  ; 
	 		
	#delimit cr  ;	
	
	*TRIM AT 1% and 99% for all continous variables
	
	foreach v in   $HH_CONSPERCAP  $HH_CONSPERCAP_long    { 
	
      _pctile `v' , p (1 99)
		replace `v' = . if `v' <= r(r1) |  `v' >= r(r2)
	}
	*
		

	global option varlabels  tex plain fragment  bdec(3)  se   starloc(1) starlevels(10 5  1) 


 ****************************************************************************************************************
  ** TABLE 1:  Determinants of U.S. out-migration between 2002 and 2005 at the household level  *****
 ****************************************************************************************************************

	
	bys folio: g hh=_n==1

	global control  hhsize     nbage13minus nbmaleage3654 nbmaleage1435  ///
		  hh_higestgrade3  hh_higestgrade4 wealthindex  wealthindexsq  ///
		   ln_socialnonlabincome  hhrelativeUS hhreturnees ///
						 
	global s0205  dead_0205 disease_0205 job_busi_failure_0205 loss_crop_0205 robb_naturaldis_0205  
	global s0298 dead_0298 disease_0298 job_busi_failure_0298 loss_crop_0298 robb_naturaldis_0298   


	outreg, clear(FIRST) 

	 qui reg  treatment   ${control}    ${s0205} i.id_mun    if rural==1  & hh==1  
			qui outreg,  merge( FIRST) ${option} keep(${s0205} ${control}  ) 
	 qui reg  treatment     ${s0205} i.id_mun    if rural==1  & hh==1 
			qui outreg,  merge( FIRST) ${option} keep(${s0205}  ) 

	  qui reg  treatment    ${control}     ${s0298} i.id_mun if rural==1  & hh==1  
		qui  outreg, merge( FIRST)  ${option} keep(${s0298} ${control}  ) 
	  qui reg  treatment     ${s0298} i.id_mun if rural==1  & hh==1 
		qui outreg,  merge( FIRST) ${option} keep(${s0298}  ) 

	nois outreg, store(e) replay(FIRST) ${option} title("TABEL 1 : Determinants migration 2005-2002 household level") 

					
 *******************************************************************************
	*TABLE 3 – Labor reallocation effects among household members left behind 
 *******************************************************************************
 
  		global labor_par    workLW   workLW_noagrw     workLW_agrw   workLW_self  agriactivity  
		global labor_h      hourLW    hourLW_noagrw  hourLW_agrw    hourLW_self  hoursagriactivity
	    global transfer    ind_rec 
		
		
	foreach LIST in labor_par labor_h  transfer  { 
	outreg, clear(A_`LIST') 
		
		global LIS 
		global LIS ${`LIST'}
			
		eststo clear 	
		foreach outcome in $LIS  {	
				
			qui su `outcome'02  if rural==1  & treatment==0 
			local av = round(r(mean), 0.001) 
			
			local a : variable label  `outcome'0502
			qui reg `outcome'0502   treatment  ${mig_control}   ${indivlist}   ${hhlist}   ///
								i.id_mun   if rural==1 , vce(cluster folio)
			outreg, merge(A_`LIST') nod  keep( treatment  )  ctitle(" ", "`a'")  ${option}	 addrows( "2002 average outcome" , `av' )							
			
			} 
					
	
	}
	*
	
	nois outreg   ,   replay(A_labor_par)   ${option} title("TABEL 2: Labor supply of non-migrant individuals") 
	nois outreg   ,   replay(A_labor_h)  ${option} title("TABLE 2:  Labor supply of non-migrant individuals")   
	

****************************************************************
	*Household Level Outcome  
 ****************************************************************
 
 	save temp, replace
	
	use temp,clear
 
	global variable_hh     hh_newmem_adu HH_work* HH_hour* HH_agri* con* HH_own* UnearnedINC* food_attana_* nonfood_attana_* HH_POS_soil_*  HH_POS_otherland*   HH_fertilizer*   HH_seedpest*   ///
			rural community_type hourLW02   workLW02  hh_self  hh_farm  ${indivlist}   ${hhlist}  ${mun_list2} ${shocks}  ///
			treatment     hhmexmigrant    HH_nb_outwork_business*  HH_nb_outworkers_land*  HH_one_outworker_land*  HH_one_outworker_business* ///
			id_mun   nbmaleage3654 nbmaleage1435 nbage55plus   farm_*  HH_incomemonth_self*  HH_*livestockincome*  HH_*cropsales* HH_*ruralsales* HH_*allfarm*
	
	* collapse data at household level 
	
	qui{	
		cap drop __* 
		foreach v of varlist $variable_hh    {
		local l`v' : variable label `v'
			if `"`l`v''"' == "" {
			local l`v' "`v'"
			di "`v'"
		}
	  }
	  
		collapse (mean)    $variable_hh    , by (folio)

		foreach v of varlist  $variable_hh	{
		label var `v' "`l`v''"
	  }
	 *
	 }
	 *
	save temp_hh, replace
	
 	
		global W wealthindex wealthindexsq
		global hhlist2  : list global(hhlist) - global(W)	
		desc $hhlist2
		

*************************************************************************************************************************
*		TABLE 2 – Effects of U.S. migration on the non-durable consumption of households left behind
*************************************************************************************************************************
 				 
	global HH_CONSPERCAP   	 food_attana_ nonfood_attana_  cons_attana_             

	foreach LIST in   HH_CONSPERCAP   { 	
		outreg, clear(A_`LIST') 
		global LIS 
		global LIS ${`LIST'}		
		foreach outcome in $LIS  {	
			
		qui su `outcome'02   if rural==1 & treatment==0 
		local av = round(r(mean), 0.001) 
		local a : variable label  `outcome'0502
		
		qui  reg `outcome'0502  treatment    ${mig_control}   ${hhlist} nbmaleage3654 nbmaleage1435 nbage55plus  i.id_mun   if  rural==1 , vce(cluster folio)				
		outreg, merge(A_`LIST') nod  keep(  treatment     )  ctitle(" ", "`a'")  ${option}		addrows( "2002 average outcome" , `av' )	
		}
		}
		*
		
		
		nois outreg    , replace  replay(A_HH_CONSPERCAP)   ${option}  title("TABLE 2") 
	
												
******************************************************************************************				
**	 TABLE 4 – Welfare effect among households without self-employed activity ** 
******************************************************************************************		
	
	use temp, clear
	
	cap drop  internal_trans0502 internal_trans0902 intern_rojas_trans0502 intern_rojas_trans0902
	g internal_trans02 =    cons_attana_02 -   INC_MONTH02 
	g internal_trans0502 =   cons_attana_0502 -   INC_MONTH0502  
	label var internal_trans0502 "internal -transfer"
	label var INC_MONTH0502 "monthly lab income" 
	
	global welf_table   cons_attana_ INC_MONTH  internal_trans   workLW_noagrw hourLW_noagrw   workLW_agrw    hourLW_agrw 
      
	*TRIM AT 1% and 99% for all continous variables
	foreach v in INC_MONTH0502  internal_trans0502  { 
      _pctile `v' , p (1 99)
		replace `v'  = . if `v' <= r(r1) |  `v' >= r(r2)
	}
	* INITIAL VALUE 2002
		foreach v in internal_trans02 INC_MONTH02 { 
				_pctile `v' if `v' >0, p ( 99)
				replace `v' = . if `v' >= r(r1) 		
	}
	*
	foreach v in INC_MONTH0502  internal_trans0502 cons_attana_0502 {
		replace `v'= . if INC_MONTH0502==. | internal_trans0502==. | cons_attana_0502 ==.  
	}
	*
	
	foreach LIST in  welf_table    { 

	outreg, clear(C_`LIST') 	
		global LIS 
		global LIS ${`LIST'}
			
		eststo clear 	
		foreach outcome in $LIS  {	
				
			qui su `outcome'02  if rural==1 & ( hh_self==0  ) & treatment==0 
			local av = round(r(mean), 0.001) 
			
			local a : variable label  `outcome'0502
		
			qui reg `outcome'0502   treatment   ${mig_control}   ${indivlist}   ${hhlist} ${shock}  ///
								i.id_mun   if  rural==1 &  hh_self==0 , vce(cluster folio) 
		
				outreg, merge(C_`LIST') nod  keep(   treatment  )  ctitle(" ", "`a'")  ${option}	addrows( "2002 average outcome" , `av' ) 		
			}
					
	}
	*
	  				 
	* WELFARE EFFECT AMONG LANDLESS HOUSEHOLD
	   nois outreg  ,    replay(C_welf_table)   ${option} title("TABLE 4") 													 
	  
	
******************************************************************************************				
**		TABLE 5 – Evidence of income effect of migration
******************************************************************************************		

	use temp_hh, clear
	
	global hh_tot   HH_workLW_self  HH_hourLW_self  HH_agriactivity   HH_hoursagriactivity 					         
	global transfer_HH UnearnedINC 
	
		foreach LIST in hh_tot  HH_CONSPERCAP  transfer_HH  { 	
			outreg, clear(A_`LIST') 
			global LIS 
			global LIS ${`LIST'}		
			foreach outcome in $LIS  {	
				
			qui su `outcome'02   if rural==1 & treatment==0 
			local av = round(r(mean), 0.001) 
			local a : variable label  `outcome'0502
			
			qui  reg `outcome'0502  treatment    ${mig_control}   ${hhlist} nbmaleage3654 nbmaleage1435 nbage55plus  i.id_mun   if  rural==1 , vce(cluster folio)
			
			* exclude wealth index from controls when dependent var = assets*
			if  ( "`LIST'"=="assets_ext" |   "`LIST'"=="assets_int" |   "`LIST'"=="assets_int_long" |   "`LIST'"=="assets_ext_long"  ) {
			 qui reg `outcome'0502   treatment    ${mig_control}   ${hhlist2} nbmaleage3654 nbmaleage1435 nbage55plus   ///
						i.id_mun   if  rural==1  , vce(cluster folio) 
			}			
			outreg, merge(A_`LIST') nod  keep(  treatment     )  ctitle(" ", "`a'")  ${option}		addrows( "2002 average outcome" , `av' )		
			}					
			}
			*	
	*INCOME EFFECTS 
	
	qui  outreg  , replace store(T1) replay(A_transfer) merge(A_transfer_HH)    ${option}				 
	nois outreg    ,   replay(T1) merge(A_hh_tot) ${option}  title("TABLE 5") 
	
	
	
		
*********************************************************************************************
***		TABLE 6 – Evidence of productivity effect among households with self-employed activity 
**********************************************************************************************

	use temp,clear
	
	qui{
		cap drop us_self us_farmer us_worker   mex_self   mex_farmer
		g us_self= treatment==1 & hh_depar_self ==1 
		g us_worker = treatment==1 & hh_depar_worker ==1 
		g us_farmer= treatment==1 & hh_depar_farmer ==1 
		g mex_self =  hhmexmigrant==1 & hh_depar_self ==1  
		g mex_farmer= hhmexmigrant==1 & hh_depar_farmer ==1  
		label var us_self "U.S. Mig * migrant self" 
		label var us_farm  "U.S. Mig * migrant farmer" 
		label var  mex_self  "Mex Mig * migrant self" 
		label var mex_farm  "Mex Mig * migrant farmer" 
	}
  
		global part_self    workLW_self  hourLW_self 
		global part_agri   agriactivity  hoursagriactivity 


		outreg, clear(B_self)
		outreg, clear(B_farm)
		
		foreach outcome in $part_self   {	
			
			qui su `outcome'02  if rural==1 & ( hh_self==1  ) & treatment==0 
			local av = round(r(mean), 0.001) 
			
			local a : variable label  `outcome'0502
	
			qui reg `outcome'0502 treatment  us_self      ${mig_control}  ${indivlist}   ${hhlist}  ${shock}  ///
						i.id_mun  if rural==1 & ( hh_self==1  )  , vce( cluster folio)		
			
			outreg, merge(B_self) nod   keep( treatment  us_self  )   ctitle(" ", "`a'")  ${option}	addrows( "2002 average outcome" , `av' )				
		}
		*
		foreach outcome in $part_agri   {	
			
			qui su `outcome'02  if   rural==1 & ( hh_farm==1 ) & treatment==0 
			local av = round(r(mean), 0.001) 
			
			local a : variable label  `outcome'0502
			
			qui reg `outcome'0502 treatment  us_farmer     ${mig_control}   ${indivlist}   ${hhlist}  ${shock}   ///
						i.id_mun    if  rural==1 & ( hh_farm==1 )    , vce( cluster folio)		
			
			outreg, merge(B_farm) nod   keep(   treatment  us_farmer    )    ctitle(" ", "`a'")  ${option}	addrows( "2002 average outcome" , `av' )				

			}
			
			*	
		nois outreg   , replace  store(e)  replay(B_self)  merge(B_farm)  ${option} title("TABLE 6 ")

			
	
